package com.order.demo.controller;

import com.order.demo.client.CommodityClient;
import com.order.demo.config.RestTemplateConfig;
import com.order.demo.entity.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import sun.rmi.runtime.Log;

import java.util.Arrays;
import java.util.List;

@RestController
public class TsetController {
    @Autowired
    private LoadBalancerClient loadBalancerClient;
    @Autowired
    private CommodityClient commodityClient;

    @RequestMapping("/order")
    public String getProductMsg(){

//        RestTemplate restTemplate = new RestTemplate();
//        ServiceInstance serviceInstance = loadBalancerClient.choose("COMMODITY");
//        String url=String.format("HTTP://%s:%s",serviceInstance.getHost(),serviceInstance.getPort())+"/test";
//        String response = restTemplate.getForObject(url,String.class);
//        String response=restTemplate.getForObject("http://COMMODITY/test",String.class);
        String response=commodityClient.commodityMsg();
        return response;
    }
    @RequestMapping("/getorderlist")
    public List<Category> getOrderList(){
        List<Category> list= commodityClient.findCategoryList(Arrays.asList("1"));
        return list;
    }
}
